﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace SportingGoodsExhibitionSystem
{
    /// <summary>
    /// peoInfo.xaml 的交互逻辑
    /// </summary>
    public partial class peoInfo : Page
    {
        public peoInfo()
        {
            InitializeComponent();
        }
        string strCon = Properties.Resources.strCON;

        string stuNum;


        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from studentInfo where studentStatus=@num", con);
            cmd.Parameters.Add("@num", SqlDbType.Int, 10).Value = 1;
            SqlDataAdapter read = new SqlDataAdapter(cmd);
            //DataTable dt = new DataTable();
            DataSet dataset = new DataSet();
            read.Fill(dataset);
            DataTable table = dataset.Tables[0];
            DataRowCollection rows = table.Rows;
            DataRow row = rows[0];
            stuNum = row["studentNumber"].ToString();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int wf = 1;
            if(fny.IsChecked==true)
            {
                wf = 1;
            }else if(fnn.IsChecked==true)
            {
                wf = 0;
            }
            int ws = 1;
            if(sny.IsChecked==true)
            {
                ws = 1;
            }else if(snn.IsChecked==true)
            {
                ws = 0;
            }
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            SqlCommand cmd = new SqlCommand("insert into peoInfo(stunum,fpeoname,fpeotele,wfhea,speoname,speotele,wshea) values(@id,@fname,@ftele,@fhea,@sname,@stele,@shea)", con);
            cmd.Parameters.Add("@id", SqlDbType.Int, 10).Value = stuNum;
            cmd.Parameters.Add("@fname", SqlDbType.VarChar, 50).Value = textFname.Text;
            cmd.Parameters.Add("@ftele", SqlDbType.VarChar, 50).Value = textFtele.Text;
            cmd.Parameters.Add("@fhea", SqlDbType.Int, 10).Value = wf;
            cmd.Parameters.Add("@sname", SqlDbType.VarChar, 50).Value = textSname.Text;
            cmd.Parameters.Add("@stele", SqlDbType.VarChar, 50).Value = textStele.Text;
            cmd.Parameters.Add("@shea", SqlDbType.Int, 10).Value = ws;
            cmd.ExecuteNonQuery();
            MessageBox.Show("填写成功");
        }
    }
}
